package hlhj.fhp.newslib.network

import android.content.Context
import android.database.Observable
import com.google.gson.Gson
import hlhj.fhp.newslib.BaseAty
import hlhj.fhp.newslib.javabean.BaseBean
import hlhj.fhp.newslib.utils.ToastUtil
import rx.Observer
import java.util.*

/**
 * Created by Administrator on 2018\6\27 0027.
 */
abstract class CommentListAction<T>(private val context:Context) : Observer<T> {
    override fun onCompleted() {

    }

    override fun onNext(t: T) {
        val str = Gson().toJson(t)
        val baseBean = Gson().fromJson(str, BaseBean::class.java)
//        val bean = t as BaseBean
        if (baseBean.code!=null){
            if (baseBean.code==1){
                onResult(t)
            }else{
                onResult(t)
               /* onNotRight()
                if (context is BaseAty){
                    context.runOnUiThread {
                        ToastUtil.toast(baseBean.message)
                        context.loadingDialog.dismiss()
                    }
                }*/
            }
        }else{
            ToastUtil.toast("网络错误")
        }
    }
    fun onNotRight(){

    }
    override fun onError(e: Throwable?) {
        e!!.printStackTrace()
//        ToastUtil.toast(e.toString())
    }
    abstract fun onResult(t:T)
}